home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
RESOURCE
/
RESOURCE.C
next >
Wrap
C/C++ Source or Header
|
1990-12-16
|
3KB
|
145 lines
/*****
* Resources.c
*
* Example of how to load resources from an external file and
* keep a handle to them in memory!
*
* by Joe Zobkiw
* AFA Zobkiw @ America Online
*
*****/
#include "Resources.h"
main()
{
int appResFile = 0;
int fileRefNum = 0;
Handle theExternalCursor = 0L;
/* you should know this by now! */
InitMacintosh();
/* show our about box */
Alert(ABOUT_ALRT,0L);
/* get the application's refnum */
appResFile = CurResFile();
CheckResError();
/* open the external file, the easy way */
fileRefNum = OpenResFile(EXTERNAL_FILENAME);
if (fileRefNum == -1) {
SysBeep(0);
ExitToShell();
}
CheckResError();
/* grab a handle to the cursor from the external file */
theExternalCursor = GetResource('CURS',EXTERNAL_CURS_ID);
CheckResError();
/* detach the resource so when we close the file it doesn't */
/* get blasted into oblivion */
DetachResource(theExternalCursor);
CheckResError();
/* close the external file */
CloseResFile(fileRefNum);
CheckResError();
/* set our application back to be the current resource file */
UseResFile(appResFile);
CheckResError();
/* this is where memory munging and all sorts of exciting things */
/* might happen before we are ever ready to use the resource that */
/* we just loaded. */
/* make sure the cursor is loaded into memory, */
/* it may have gotten biffed! */
LoadResource(theExternalCursor);
CheckResError();
/* now set the cursor to the external resource */
SetCursor((CursHandle)*theExternalCursor);
while (! Button() ) { ; }
/* flush the mouseclick and init the cursor */
FlushEvents(everyEvent,0);
InitCursor();
}
/********************************************************
*
* check ResError and alert the user if error
*
********************************************************/
CheckResError()
{
int error;
error = ResError();
if (error != noErr) {
switch(error) {
resNotFound:
DoAlert("\presNotFound - Resource not found.",error);
break;
resFNotFound:
DoAlert("\presFNotFound - Resource file not found.",error);
break;
default:
DoAlert("\pUnknown error",error);
break;
}
ExitToShell();
}
}
/********************************************************
*
* initialize the Macintosh
*
********************************************************/
InitMacintosh()
{
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent,0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
}
/********************************************************
*
* show an error alert
*
********************************************************/
DoAlert(char *theString, int errID)
{
char *theErrID;
NumToString(errID,theErrID);
ParamText(theString,theErrID,0L,0L);
Alert(ALRT_ID, 0L);
}
/********************************************************
*
* set the cursor to cursorID
*
********************************************************/
SetMyCursor( cursorID )
int cursorID;
{
CursHandle theCursor;
theCursor = GetCursor(cursorID);
SetCursor(*theCursor);
}